package com.app;

import com.app.services.MailSrv;
import com.app.thread.Threads;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Hendra on 12/24/2014.
 */
public class Main {

    /** The Constant logger. */
    private final static Logger logger = LoggerFactory.getLogger(Main.class);

    /** The logger thread. */
    private static volatile Thread loggerThread; // start and stop are called

    private static boolean stop = false;

    public static void start(String[] args) {
        logger.info("start");

        while (!stop) {
            startThread();
            try {
                loggerThread.sleep(10000);
            } catch (InterruptedException e) {
                //ignore
            }

        }
        logger.info("running");
    }

    public static void stop(String[] args) {
        if (loggerThread != null) {
            stop = true;
            logger.info("Interrupting the thread");
            loggerThread.interrupt();
        } else {
            logger.info("No thread to interrupt");
        }
    }

    public static void main(String[] args) {
//        if ("start".equals(args[0])) {
//            start(args);
//        } else if ("stop".equals(args[0])) {
//            stop(args);
//        }
        MailSrv mailSrv = new MailSrv();
        mailSrv.service();
    }

    private static void startThread() {
        loggerThread = new Thread(new Threads());
        loggerThread.start();
    }
}
